import cn.xy.dao.TeacherMapper;
import cn.xy.pojo.Teacher;
import cn.xy.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class test {
    //已开启事务自动提交
    SqlSession sqlSeesion = null;
    TeacherMapper mapper = null;

    //测试之前执行
    @Before
    public void beFore(){
        sqlSeesion = MybatisUtils.getSqlSeesion();
        mapper = sqlSeesion.getMapper(TeacherMapper.class);
    }

    //测试之后执行
    @After
    public void after(){
        sqlSeesion.close();
    }

    @Test
    public void test01(){
        //使用注解查询
        SqlSession sqlSeesion = MybatisUtils.getSqlSeesion();
        TeacherMapper mapper = sqlSeesion.getMapper(TeacherMapper.class);
        List<Teacher> teacherList = mapper.getTeacherList();
        for (Teacher teacher : teacherList) {
            System.out.println(teacher);
        }
        sqlSeesion.close();
    }

    @Test
    public void test02(){
        //增
        mapper.insertTeacher(new Teacher(4,"王老师",1));
    }

    @Test
    public void test03(){
        //删
        mapper.deleteTeacher(4);
    }

    @Test
    public void test04(){
        //改
        mapper.updateTeacher(new Teacher(3,"孙老师",1));
    } @Test


    public void test05(){
        //查
        System.out.println(mapper.selectTeacher(1));
    }
}
